home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-03-04 | 2.1 KB | 100 lines | [TEXT/ToyS] |
- on open fsObjs
- set n to the number of items of fsObjs
- set pf to PrimeFactor(n)
-
- if (the number of items of pf) is not 2 then
- -- Ask user for number vertical, since we can't figure it out
- display dialog ("The number of icons (" & n & ") does not have exactly two prime factors." & return ¬
- & return & "Please enter the number of lines of icons needed for the image.") ¬
- default answer (n / (item 2 of pf)) ¬
- buttons {"Cancel", "OK"} ¬
- default button 2
-
- set v to n / (the text returned of the result)
- else
- display dialog ("How many lines of icons are needed?") ¬
- buttons {item 1 of pf, item 2 of pf} ¬
- default button 2
-
- set v to the button returned of the result
- end if
-
- set fsObjs to SortFileList(fsObjs)
-
- set h to n / v
- set x to 32
- set y to 32
- set i to 1
-
- repeat with fsObj in fsObjs
- SetPosition(fsObj, x, y)
- set i to i + 1
- set x to x + 32
- if (i > h) then
- set y to y + 32
- set x to 32
- set i to 1
- end if
- end repeat
- end open
-
-
- on PrimeFactor(n)
- set pf to {}
-
- repeat while n > 3
- repeat with i from 2 to 111
- if (n mod i) is 0 then
- set n to n / i
- set pf to pf & {i}
- exit repeat
- end if
- end repeat
- end repeat
-
- return pf
- end PrimeFactor
-
-
- on SortFileList(fsObjs)
- -- Insertion sort
- set tList to {}
- set fList to {}
- set cnt to 0
- repeat with fsObj in fsObjs
- set fname to catalog name of (basic info for fsObj)
- set n to 0
- repeat with t in tList
- if (fname > t) then
- set n to n + 1
- else
- exit repeat
- end if
- end repeat
-
- if (n is 0) then
- set tList to {fname} & tList
- set fList to {fsObj} & fList
- else if (n is cnt) then
- set tList to tList & {fname}
- set fList to fList & {fsObj}
- else
- set tList to (items 1 through n of tList) & fname & (items (n + 1) through -1 of tList)
- set fList to (items 1 through n of fList) & fsObj & (items (n + 1) through -1 of fList)
- end if
- set cnt to cnt + 1
- end repeat
-
- return fList
- end SortFileList
-
-
- on SetPosition(fsObj, x, y)
- -- Set the position of a file's icon in a folder to x,y
- try
- tell application "Finder" to set the position of fsObj to {x, y}
- on error
- beep
- end try
- end SetPosition
-